package com.sg.hms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sg.hms.Service.H_ApplicationService;
import com.sg.hms.ServiceImpl.H_ApplicationServiceImpl;

import net.sf.json.JSONObject;
/**
 * 
 * @author 王奇霞
 *
 */
public class H_SearchApplicationController extends HttpServlet{
    private H_ApplicationService haService=new H_ApplicationServiceImpl();
	@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	// TODO Auto-generated method stub
    	doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	// TODO Auto-generated method stub
    	req.setCharacterEncoding("utf-8");
    	resp.setCharacterEncoding("utf-8");
    	PrintWriter pw=resp.getWriter();
    	String applicationDate=req.getParameter("applicationDate");//获得查询日期
    	String state=req.getParameter("state");
    	
    	//System.out.println(applicationDate);
    	int page=Integer.parseInt(req.getParameter("page"));
    	int pagesize=Integer.parseInt(req.getParameter("rows"));
    	if(state==null){
    		state="已提交";
    	}
    	
    	int start=(page-1)*pagesize;
    	JSONObject apps=null;
    	if(applicationDate==null||applicationDate==""){
    		apps=haService.searchapplication(start, pagesize,state);
    	}else{
    		apps=haService.searchapplication(start, pagesize, applicationDate,state);
    	}
    	
    	//System.out.println(apps);
    	pw.write(apps.toString());
    }
}
